package com.fudan.backend.controller;

import com.fudan.backend.exception.RetCode;
import com.fudan.backend.pojo.StoreDeleteRequest;
import com.fudan.backend.service.StoreDeleteRequestService;
import com.fudan.backend.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/store")
public class StoreDeleteRequestController {
    @Autowired
    StoreDeleteRequestService storeDeleteRequestService;

    @PostMapping("/delete-request/add/{storeId}")
    public R addStoreDeleteRequest(@PathVariable("storeId") String storeId){
        RetCode retCode = storeDeleteRequestService.addStoreDeleteRequest(storeId);
        return new R(retCode);
    }

    @PostMapping("/delete-request/process")
    public R processStoreDeleteRequest(@RequestBody StoreDeleteRequest storeDeleteRequest){
        RetCode retCode = storeDeleteRequestService.processStoreDeleteRequest(storeDeleteRequest);
        return new R(retCode);
    }

    @GetMapping("/delete-request")
    public R getAllStoreDeleteRequest(int current, int size){
        PageInfo<StoreDeleteRequest> page = storeDeleteRequestService.getAllStoreDeleteRequest(current, size);
        Map<String, Object> ret = new HashMap<>();
        ret.put("storeDeleteRequestList", page.getList());
        ret.put("total", page.getTotal());
        return new R(RetCode.STORE_DELETE_REQUEST_SUCCESS,ret);
    }

    @GetMapping("/delete-request/{deleteRequestId}")
    public R getStoreDeleteRequestByStoreDeleteRequestId(@PathVariable("deleteRequestId") String storeDeleteRequestId){
        StoreDeleteRequest storeDeleteRequest = storeDeleteRequestService.getStoreDeleteRequestByStoreDeleteRequestId(storeDeleteRequestId);
        return new R(RetCode.STORE_DELETE_REQUEST_SUCCESS,storeDeleteRequest);
    }

    @GetMapping("/delete-request/seller/{userId}")
    public R getAllStoreDeleteRequestByUserId(int current, int size,@PathVariable("userId") String userId){
        PageInfo<StoreDeleteRequest> page = storeDeleteRequestService.getAllStoreDeleteRequestByUserId(current, size, userId);
        Map<String, Object> ret = new HashMap<>();
        ret.put("storeDeleteRequestList", page.getList());
        ret.put("total", page.getTotal());
        return new R(RetCode.STORE_DELETE_REQUEST_SUCCESS,ret);
    }
}
